$(document).ready(function() {
    if($("#galleria").length != 0) {
        Galleria.loadTheme('themes/classic/galleria.classic.min.js');
        Galleria.configure({
            lightbox: true,
            showCounter:false,
            transition:'fade',
            autoplay:2000
        });
        Galleria.run('#galleria');
    }
    $('.title-tooltip').tooltip({ 
        track: true, 
        delay: 0, 
        showURL: false, 
        showBody: " | ", 
        fade: 250 
    });
    $("#nav li ul").hide();	
    $("#nav li").hover(function(){
        $(this).find("ul").hide('fast');
        $("#nav li:not(.nav-current)").removeClass("active");
        $("ul",this).slideDown().css({
            visibility:'visible'
        });
        $(this).addClass("active");
    }, function(){
        $("ul",this).slideUp();
        $(this).not(".nav-current").removeClass("active");
    });
    var screenHeight = $(document).height();
    var footerHeight = $("#footer").height();
    $("#container").css('min-height',(screenHeight - footerHeight) + 'px');
    $(".tabs").click(function() {
        $rel = $(this).attr('rel');
        $block = $(this).attr('block');
        $("ul."+$block+' li').removeClass("active");
        $('li.'+$rel).addClass('active');
        $("div."+$block).hide();
        $('#tab-'+$rel).show();
        return false;
    });
    if($("#news-content").length != 0) {
        sildeNews();
        $("#news-content .relate ul li").hover(function() {
            if (typeof(timeOut) != 'undefined') {
                clearTimeout(timeOut);
            }
            var largeContent = $("#news-content .large");
            var nextNews = $(this);
            var nextId = nextNews.attr('id');
            var strImg = nextNews.find('img').attr('src');
            var desImg = nextNews.find('span').text();  
            var href = nextNews.find('a').attr('href');
            largeContent.attr('current', nextId);
            largeContent.find('a').attr('href', href);
            largeContent.find('img').attr('src', strImg);
            largeContent.find('a').html(desImg);
        }, function() {
            timeOut = setTimeout("sildeNews()", 3000);
        });
    }
//    getOTCInfo();
});

//function getOTCInfo()
//{
//    var host = 'http://tamtrikhoemanh.health.vn/slir/getOTCInfo.php';
//    var callbackFunc = function(data, yyy) {
//        console.log(data);
//    }
//    $.ajax({
//        url:host,
//        dataType:'jsonp',
//        jsonpCallback:callbackFunc
//    });
//}

function sildeNews()
{
    var largeContent = $("#news-content .large");
    var currNewsId = largeContent.attr('current');
    var strImg = '';
    var desImg = '';
    var nextNews = '';
    var href = '';
    var nextId = '';
    if(currNewsId=='') {
        nextNews = $("#news-content .relate ul li").first();
        nextId = nextNews.attr('id');
        strImg = nextNews.find('img').attr('src');
        desImg = nextNews.find('span').text();  
        href = nextNews.find('a').attr('href');
    } else {
        var number = currNewsId.replace('news-','');
        if(eval(number) < 4) {
            number++;
        } else {
            number = 1;
        }
        nextNews = $("#news-content .relate ul li#news-"+number);
        nextId = nextNews.attr('id');
        strImg = nextNews.find('img').attr('src');
        desImg = nextNews.find('span').text();  
        href = nextNews.find('a').attr('href');
    }
    largeContent.attr('current', nextId);
    largeContent.find('a').attr('href', href);
    largeContent.find('img').attr('src', strImg);
    largeContent.find('a').html(desImg);
    timeOut = setTimeout("sildeNews()", 3000);
}